package com.ser02;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ServletTest4")
public class ServletTest4 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf-8");

        String parameter = req.getParameter("username");
        System.out.println(parameter);//tom

        //Enumeration<String> parameterNames = req.getParameterNames();
        //while (parameterNames.hasMoreElements()){
        //    String nextElement = parameterNames.nextElement();
        //    System.out.println(nextElement + "..." + req.getParameter(nextElement));//username...qwe  //password...qwe
        //}

        //String[] usernames = req.getParameterValues("username");
        //for (String str : usernames) {
        //    System.out.println(str);//qwe123
        //}

        //String[] usernames = req.getParameterValues("hobby");
        //for (String str : usernames) {
        //    System.out.println(str);//qwe123
        //}

        //Map<String, String[]> parameterMap = req.getParameterMap();
        //Set<Map.Entry<String, String[]>> set = parameterMap.entrySet();
        //for (Map.Entry<String, String[]> entry : set) {
        //    String key = entry.getKey();
        //    System.out.println(key);
        //    String[] value = entry.getValue();
        //    for (String v : value) {
        //        System.out.println(v);
        //    }
        //    System.out.println("-------------");
        //}

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
